package com.atguigu.day22.tcpsocket.s2;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.Scanner;

/**
 * @version 1.0
 * @Author 马冰
 * @Date 2024/11/27 10:47
 * @注释
 */
public class Client2 {
    public static void main(String[] args) {
        //创建客户端对象
        try (Socket socket = new Socket(InetAddress.getLocalHost(), 11111);
             //获取字节输出流
            OutputStream os = socket.getOutputStream();
            //转为打印流
            PrintStream ps = new PrintStream(os);
            //获取字节输入流
             InputStream is = socket.getInputStream();
            //创建Scanner
             Scanner sc = new Scanner(is);
             //创建键盘输入
             Scanner input = new Scanner(System.in);
        ) {

            //写出数据
            while (true) {
                System.out.println("请您输入一句话");
                String massage = sc.next();
                //写出数据
                ps.println(massage);
                //读取数据并展示
                String ip = sc.nextLine();
                ps.println("服务端返回的数据时: " + ip);
            }


        } catch (Exception e) {
            throw new RuntimeException(e);
        }

    }
}
